<?php
/**
 * Created by PhpStorm.
 * User: Dave
 * Date: 2018/5/29
 * Time: 15:07
 */

namespace Biz\model\smallenergy;

class SmallEnergyShop  extends \Doraemon\pockets\datebase\BaseDbModel
{
    const _CONFIG_FILE_ = 'db_im';

    const _CONFIG_SELECT_ = 'db_im';

    const _DATABASE_ = 'hhz_im';

    const _TABLE_NAME = 'hhz_smallenergy_shop';

    const STATUS_NORMAL = 1;
    const STATUS_DELETE = 9;

    public static function getShopListByGroupIds($groupIds, $field = '*')
    {
        return self::select($field, [
            'AND' => [
                'pre_sale_reception_group_id'=>$groupIds,
                'status' => self::STATUS_NORMAL,
            ]
        ]);
    }

    public static function getShopByGroupId($groupIds, $field = '*')
    {
        return self::get($field, [
            'AND' => [
                'pre_sale_reception_group_id'=>$groupIds,
                'status' => self::STATUS_NORMAL,
            ]
        ]);
    }

    public static function getShopInfoByShopIds($shopIds, $field = '*')
    {
        return self::select($field, [
            'AND' => [
                'shop_id'=>$shopIds,
                'status' => self::STATUS_NORMAL,
            ]
        ]);
    }

    public static function getShopByShopId($shopId, $field = '*')
    {
        return self::get($field, [
            'AND' => [
                'shop_id'=>$shopId,
                'status' => self::STATUS_NORMAL,
            ]
        ]);
    }

    public static function getSmallEnergyInfoById($id, $field = '*')
    {
        return self::get($field, [
            'AND' => [
                'id'=>$id,
                'status' => self::STATUS_NORMAL,
            ]
        ]);
    }

    public static function getSmallEnergyList($where = ' 1=1 ', $field = '*')
    {
        return self::select($field,[
            'status'=> self::STATUS_NORMAL,
            'ORDER' => ['addtime'=>'DESC']
        ]);
    }

    public static function addSmallEnergy($data)
    {
        if (self::insert($data)->rowcount()) {
            return self::id();
        }
    }

    public static function updateSmallEnergy($smallenergyId, $data)
    {
        if (self::update($data, ['id'=> $smallenergyId])->rowcount()) {
            return $smallenergyId;
        }
    }

    public static function delSmallEnergyByShopId($shopId)
    {
        if (self::update(['status' =>self::STATUS_DELETE], ['shop_id'=> $shopId])->rowcount()) {
            return $shopId;
        }
    }

}